-- =============================================
-- Procedure: RemoveCancelledReducingBalanceLoan
-- Purpose:	Remove reducing balance record because they are cancelled
-- Author: Dale McFarlane
-- Created: 2013-1-27
-- Modification History
-- Modified By	Modification Date	Reason
-- =====================================================================================
--  
-- =====================================================================================

-- EXEC 

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[RemoveCancelledReducingBalanceLoan]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
BEGIN
	DROP PROCEDURE dbo.[RemoveCancelledReducingBalanceLoan]
END
GO

CREATE PROCEDURE RemoveCancelledReducingBalanceLoan
@loan_no varchar(16),
@error_code int OUT,
@error_msg varchar(512) OUT

AS
BEGIN
	DECLARE @user_id BIGINT
	
	BEGIN TRANSACTION
	
	BEGIN TRY	
		DELETE FROM loan_redbal
		WHERE loan_no = @loan_no
		
	END TRY
	BEGIN CATCH
		SET @error_code = @@ERROR
		SET @error_msg = ERROR_MESSAGE()
	END CATCH
	
	IF @error_code IS NOT NULL 
	BEGIN
		ROLLBACK TRANSACTION;
	END
	ELSE
	BEGIN
		COMMIT TRANSACTION;
	END
END
GO